"""
线索页面编辑线索用例（必选项合法输入）
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
from selenium.webdriver.support.select import Select
#定位器


name_locator = (By.NAME, "name")
password_locator = (By.NAME, "password")
login_locator = (By.CSS_SELECTOR, "body > div.container > div > div.span4 > div > form > fieldset > input.btn.btn-primary")
xs_link_locator =(By.LINK_TEXT,"线索")
xs_table_locator = (By.CSS_SELECTOR,"#form1 > table > tbody")
xs_table_ck_element_locator = (By.LINK_TEXT,"查看")
xs_xsxq_xg_locator = (By.LINK_TEXT,"修改")
xs_bjxs_xsfzr_locator = (By.ID,"owner_name")
xs_bjxs_ly_locator = (By.ID,"source")
xs_bjxs_zw_locator = (By.ID,"position")
xs_bjxs_sj_locator = (By.ID,"mobile")
xs_bjxs_sf_locator = (By.NAME,"address['state']")
xs_bjxs_cs_locator = (By.NAME,"address['city']")
xs_bjxs_dq_locator = (By.NAME,"address['area']")
xs_bjxs_jd_locator = (By.NAME,"address['street']")
xs_bjxs_xclxsj_locator = (By.ID,"nextstep_time")
xs_bjxs_gsm_locator = (By.ID,"name")
xs_bjxs_lxrxm_locator = (By.ID,"contacts_name")
xs_bjxs_zc_locator = (By.ID,"saltname")
xs_bjxs_yx_locator = (By.ID,"email")
xs_bjxs_xclxnr_locator = (By.ID,"nextstep")
xs_bjxs_bz_locator = (By.ID,"description")
xs_bjxs_bc_locator = (By.CSS_SELECTOR,"#form1 > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")
xs_bjxs_kb_locator = (By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(7) > td:nth-child(3)")


#所需数据
name = "admin"
password = "123456"
xsfzr = "胡雨龙"
jd = "天府广场"
xclxsj = "2023-03-31 13:52"
xclxnr = "签订合同"
gsm = "HD"
bz = "合作愉快"
lxrxm = "GGG"
sj = "13408003620"
yx = "333@qq.com"
zw = "技术经理"
#操作
#打开浏览器
driver = webdriver.Chrome()
#最大化窗口
driver.maximize_window()
#进入悟空CRM登录界面
driver.get("http://192.168.1.25/crm/")
#输入用户名
driver.find_element(*name_locator).send_keys(name)
#输入密码
driver.find_element(*password_locator).send_keys(password)
#点击确定按钮
driver.find_element(*login_locator).click()
#点击线索按钮
driver.find_element(*xs_link_locator).click()
#找到线索列表
tabele = driver.find_element(*xs_table_locator)
#点击查看按钮
tabele.find_element(*xs_table_ck_element_locator).click()
#点击修改按钮
driver.find_element(*xs_xsxq_xg_locator).click()
#输入线索负责人
driver.find_element(*xs_bjxs_xsfzr_locator).clear()
driver.find_element(*xs_bjxs_xsfzr_locator).send_keys(xsfzr)
#选择来源
source = driver.find_element(*xs_bjxs_ly_locator)
Select(source).select_by_index(2)
#输入职位
driver.find_element(*xs_bjxs_zw_locator).clear()
driver.find_element(*xs_bjxs_zw_locator).send_keys(zw)
#输入手机
driver.find_element(*xs_bjxs_sj_locator).clear()
driver.find_element(*xs_bjxs_sj_locator).send_keys(sj)
#选择地址
state = driver.find_element(*xs_bjxs_sf_locator)
Select(state).select_by_index(1)
city = driver.find_element(*xs_bjxs_cs_locator)
Select(city).select_by_index(1)
area = driver.find_element(*xs_bjxs_dq_locator)
Select(area).select_by_index(1)
#输入街道信息
driver.find_element(*xs_bjxs_jd_locator).clear()
driver.find_element(*xs_bjxs_jd_locator).send_keys(jd)
#输入下次联系时间
driver.find_element(*xs_bjxs_xclxsj_locator).clear()
driver.find_element(*xs_bjxs_xclxsj_locator).send_keys(xclxsj)
#输入公司名
driver.find_element(*xs_bjxs_gsm_locator).clear()
driver.find_element(*xs_bjxs_gsm_locator).send_keys(gsm)
#输入联系人姓名
driver.find_element(*xs_bjxs_lxrxm_locator).clear()
driver.find_element(*xs_bjxs_lxrxm_locator).send_keys(lxrxm)
#选择尊称
saltname = driver.find_element(*xs_bjxs_zc_locator)
Select(saltname).select_by_index(1)
#输入邮箱
driver.find_element(*xs_bjxs_yx_locator).clear()
driver.find_element(*xs_bjxs_yx_locator).send_keys(yx)
#输入下次联系内容
driver.find_element(*xs_bjxs_xclxnr_locator).clear()
driver.find_element(*xs_bjxs_xclxnr_locator).send_keys(xclxnr)
#输入备注
driver.find_element(*xs_bjxs_bz_locator).clear()
driver.find_element(*xs_bjxs_bz_locator).send_keys(bz)
#点击空白处
driver.find_element(*xs_bjxs_kb_locator).click()
#点击保存
driver.find_element(*xs_bjxs_bc_locator).click()

sleep(5)
#关闭浏览器
driver.quit()
if __name__ == '__main__':
    unittest.main()

